﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
#if !WINDOWS_PHONE


#endif

namespace DARE
{
    [AttrTypeDependentSerializable(typeof(DARE.Save.DataStructures.CPlaneModelData))]
    public class CPlaneModel : CBasicModel
    {

    #region ctor

        public CPlaneModel() : 
            base()
        {
            Initialize();
        }

        public CPlaneModel(string name) : 
            base(name)
        {
            Initialize();
        }

        public CPlaneModel(float size) : 
            base(size, 0, size)
        {
            Initialize();
        }

        public CPlaneModel(string name, float size) : 
            base(name, size, 0, size)
        {
            Initialize();
        }

        public void Initialize()
        {
            //m_cullMode = CullMode.None;
            m_size.Y = 0;
            CullMode = CullMode.None;
            SetupVertices();
            CreateVertexBuffer();
        }

        public override AModel Clone()
        {
            CPlaneModel clone = new CPlaneModel(m_name, m_size.X);

            base.CopyPropertiesTo(clone);
            return clone;
        }

    #endregion

    #region setup

        protected void SetupVertices()
        {
#if WINDOWS_PHONE
            m_vertices = new VertexPositionNormalTexture[6];
#else
            m_vertices = new VertexPositionNormalTextureTangentBinormal[6];
#endif
            m_size.X /= 2.0f;
            m_size.Z /= 2.0f;

            // points definition
            Vector3 leftFront = new Vector3(-m_size.X, m_size.Y, m_size.Z);
            Vector3 rightFront = new Vector3(m_size.X, m_size.Y, m_size.Z);
            Vector3 leftBack = new Vector3(-m_size.X, m_size.Y, -m_size.Z);
            Vector3 rightBack = new Vector3(m_size.X, m_size.Y, -m_size.Z);

            // plane
#if WINDOWS_PHONE
            m_vertices[0] = new VertexPositionNormalTexture(rightBack, Vector3.UnitY, Vector2.UnitY);
            m_vertices[1] = new VertexPositionNormalTexture(rightFront, Vector3.UnitY, Vector2.One);
            m_vertices[2] = new VertexPositionNormalTexture(leftFront, Vector3.UnitY, Vector2.UnitX);
            m_vertices[3] = new VertexPositionNormalTexture(leftBack, Vector3.UnitY, Vector2.Zero);
            m_vertices[4] = new VertexPositionNormalTexture(rightBack, Vector3.UnitY, Vector2.UnitY);
            m_vertices[5] = new VertexPositionNormalTexture(leftFront, Vector3.UnitY, Vector2.UnitX);
#else
            m_vertices[0] = new VertexPositionNormalTextureTangentBinormal(rightBack, Vector3.UnitY, Vector2.UnitY);
            m_vertices[1] = new VertexPositionNormalTextureTangentBinormal(rightFront, Vector3.UnitY, Vector2.One);
            m_vertices[2] = new VertexPositionNormalTextureTangentBinormal(leftFront, Vector3.UnitY, Vector2.UnitX);
            m_vertices[3] = new VertexPositionNormalTextureTangentBinormal(leftBack, Vector3.UnitY, Vector2.Zero);
            m_vertices[4] = new VertexPositionNormalTextureTangentBinormal(rightBack, Vector3.UnitY, Vector2.UnitY);
            m_vertices[5] = new VertexPositionNormalTextureTangentBinormal(leftFront, Vector3.UnitY, Vector2.UnitX);
#endif
        }

    #endregion

    }
}
